<?php
class tokens_model extends CI_Model {
	public function __construct()
    {
		parent::__construct();
		$this->load->database();
    }
	
	/* Basic DB opeartion*/
    
	public function get_all()
    {
		$query = $this->db->get('tokens');
		return $query->result_array();
    }
  
    public function get_by_id($tok_id)
    {
		$query = $this->db->get_where('tokens', array('tok_id' => $tok_id));
		return $query->row_array();
    }
  
    public function insert($data)
    {
		$this->db->insert('tokens',$data);
		return $this->db->insert_id();
	}
	
    public function update($tok_id,$data)
    {
		$this->db->update('tokens', $data, array('tok_id' => $tok_id));
		return $this->db->affected_rows();
    }
	
	public function delete($tok_id)
	{
		$this->db->delete('tokens', array('tok_id' => $tok_id)); 
		return $this->db->affected_rows();
	}
	
	/*Business logic opeartion*/
	public function get_by_key($tok_key)
    {
		$query = $this->db->get_where('tokens', array('tok_key' => $tok_key));
		return $query->row_array();
    }
}
?>
